import React from 'react'
import  routeConfig from './routeConfig'
import { Route,Switch } from 'react-router-dom'

function getRoutes(routeConfig){
  if(!routeConfig){
      return null
  }
  const route =  routeConfig.map((item,i)=>{
    const {children,component: Component,...rest} = item
    return <Route {...rest} key={i} 
      render={
        values=>{
          return <Component {...values}>
             { getRoutes(children)}
          </Component>
        }
      }
    />
  })

  return (
    <Switch>
      {route}
    </Switch>
  )
}
export default function RootRouter() {
  return (
    <>
    {
      getRoutes(routeConfig)
      }
      </>
  )
}
